package org.example.algorithm.sliding;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

public class FindRepeatedDnaSequencesSolution {

    public static void main(String[] args) {
        String s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT";
        FindRepeatedDnaSequencesSolution solution = new FindRepeatedDnaSequencesSolution();
        List<String> res = solution.findRepeatedDnaSequences(s);
        System.out.println(res);
    }

    public List<String> findRepeatedDnaSequences(String s) {
        if (s.length() < 10) {
            return new ArrayList<>();
        }
        HashSet<String> set = new HashSet<>();
        HashSet<String> strSet = new HashSet<>();
        for (int i=0;i<s.length()-10+1;i++) {
            String tempStr = s.substring(i, i+10);
            if (set.contains(tempStr)) {
                strSet.add(tempStr);
            } else {
                set.add(tempStr);
            }
        }
        return new ArrayList<>(strSet);
    }
}
